<!--
 * @Description:
 * @Date: 2021-05-27 12:29:22
 * @LastEditTime: 2021-08-16 14:49:34
-->
<template>
  <div v-loading="loading" class="app-container">
    <el-form ref="form" :model="form" :rules="rules">
      <el-form-item prop="defaultContract.supplier">
        <ckEditor :past-editor.sync="form.defaultContract.supplier" :is-read-only="false" />
      </el-form-item>
      <div class="dialog-footer-center">
        <span v-action="'config@save'">
          <el-button type="primary" :loading="btnLoading" @click="submitForm">保存</el-button>
        </span>
      </div>
    </el-form>
  </div>
</template>

<script>
import {
  action
} from '@/directive/permission/index.js' // 权限判断指令
export default {
  name: 'DefaultContract',
  directives: {
    action
  },
  data() {
    return {
      defaultContract: '',
      form: {
        defaultContract: {
          supplier: ''
        },
        parent: 'defaultContract'
      },
      rules: {},
      btnLoading: false,
      loading: false
    }
  },
  computed: {},
  created() {
    const vm = this
    vm.getDefaultContract()
  },
  methods: {
    getDefaultContract() {
      const vm = this
      vm.loading = true
      vm.$http.get('/config/defaultContract').then(res => {
        vm.form.defaultContract.supplier = res.data.defaultContract.supplier
        vm.loading = false
      }).catch(() => {
        vm.loading = false
      })
    },

    // 提交表单
    submitForm() {
      const vm = this
      vm.$refs.form.validate(valid => {
        if (valid) {
          vm.btnLoading = true
          vm.$http.post('/config', vm.form).then(res => {
            vm.getDefaultContract()
            vm.$message.success('编辑成功')
            vm.btnLoading = false
          }).cathc(() => {
            vm.btnLoading = false
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
